package com.await.biubiu;

import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.graphics.Path;
import android.os.Bundle;

import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.google.android.material.floatingactionbutton.FloatingActionButton;

import java.util.Timer;
import java.util.TimerTask;


public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private FloatingActionButton button;
    private TextView textView1;
    private TextView textView2;
    private TextView textView3;
    private TextView textView4;
    private FloatingActionButton button2;
    private FloatingActionButton button3;
    private FloatingActionButton button4;
    private Path path;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button = (FloatingActionButton) findViewById(R.id.button);
        textView1 = findViewById(R.id.tv1);
        textView2 = findViewById(R.id.tv2);
        textView3 = findViewById(R.id.tv3);
        textView4 = findViewById(R.id.tv4);

        button.setOnClickListener(this);
        //绘制贝塞尔曲线
        path = new Path();
        path.quadTo(500, 975, 0, 1920);

    }
    public void reset(View v){
        button.setX(0);
        textView1.setX(0);
        textView2.setX(0);
        textView3.setX(0);
        textView4.setX(0);
        button.setY(0);
        textView1.setY(0);
        textView2.setY(0);
        textView3.setY(0);
        textView4.setY(0);
    }

    @Override
    public void onClick(View v) {
        ObjectAnimator mAnimator = ObjectAnimator.ofFloat(button, View.X, View.Y, path);
        System.out.println(mAnimator.setDuration(5000));
        mAnimator.start();


        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                ObjectAnimator mAnimator1 = ObjectAnimator.ofFloat(textView1, View.X, View.Y, path);
                mAnimator1.setDuration(5000);
                mAnimator1.start();
            }
        }, 1000);
        Handler handler1 = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                ObjectAnimator mAnimator1 = ObjectAnimator.ofFloat(textView2, View.X, View.Y, path);
                mAnimator1.setDuration(5000);
                mAnimator1.start();
            }
        }, 2000);
        Handler handler2 = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                ObjectAnimator mAnimator1 = ObjectAnimator.ofFloat(textView3, View.X, View.Y, path);
                mAnimator1.setDuration(5000);
                mAnimator1.start();
            }
        }, 3000);
        Handler handler3 = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                ObjectAnimator mAnimator1 = ObjectAnimator.ofFloat(textView4, View.X, View.Y, path);
                mAnimator1.setDuration(5000);
                mAnimator1.start();
            }
        }, 4000);
    }
}